package com.jian.socks5.tcp.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.util.CharsetUtil;

import java.util.List;

public class ClientInMessgeHandler extends MessageToMessageDecoder<FullHttpResponse> {

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
        System.err.println("ClientInMessgeHandler:" + cause.getMessage());
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, FullHttpResponse msg, List<Object> out) throws Exception {
        //ByteBuf content = msg.content();
        ByteBuf content = msg.content();
        //HttpHeaders headers = msg.headers();
        String s = content.toString(CharsetUtil.UTF_8);
        System.out.println("编号：" + s);
        //System.out.println("内容:" + System.getProperty("line.separator") + content.toString(CharsetUtil.UTF_8));
        //System.out.println("头:" + System.getProperty("line.separator") + headers.toString());

    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
    }
}
